/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import {
  Form, Input, Radio, Select, Typography,
  Upload, Tooltip, DatePicker, Button,InputNumber
} from 'antd';
import {connect} from 'dva';
import ReactDataGrid from 'react-data-grid';
import moment from 'moment'
import find from 'lodash/find'
import request from '@/utils/request';
const { Text } = Typography;
const FormItem = Form.Item;
const { TextArea } = Input;
const RadioGroup = Radio.Group;
const Option = Select.Option;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      users:[],
      fileList:[],
      meterArr: [],
    }
  }

  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 8},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      }
    };
    const props = {
      onRemove: (file) => {
        this.setState(({ fileList }) => {
          const index = fileList.indexOf(file);
          const newFileList = fileList.slice();
          newFileList.splice(index, 1);
          return {
            fileList: newFileList,
          };
        });
      },
      beforeUpload: (file) => {
        this.setState(({ fileList }) => ({
          fileList: [file],
        }));
        return false;
      },
      fileList: this.state.fileList,
    };
    const {getFieldDecorator} = this.props.form;

    return (
      <div>
        <Form onSubmit={this.handleSubmit} >
          <Form.Item label="所属分站"
                     {...formItemLayoutWithLabel}
          >
            {getFieldDecorator('company_id', {
              initialValue:sessionStorage.getItem('company_id'),
              rules: [{required: true, message:'所属分站不能为空'}],
            })(
              <Select  disabled={Boolean(sessionStorage.getItem('company_id'))||this.props.editRecord} placeholder="请选择">
                {
                  JSON.parse(sessionStorage.getItem('management_companies')).map((item,index)=>{
                    return <Option key={index} value={item.id}>
                      {item.name}
                    </Option>
                  })
                }
              </Select>,
            )}
          </Form.Item>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               开始导入行号
            </span>
            )}
          >
            {getFieldDecorator('start_row', {
                initialValue: '2',
                  rules: [{required: true, message:''}],
            })(
              <InputNumber  min={2} style={{width:'100%'}}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               结束导入行号
            </span>
            )}
          >
            {getFieldDecorator('end_row', {
                initialValue: '',
            })(
              <InputNumber  min={2} style={{width:'100%'}}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={'选择EXCEL文件'}
          >
            {getFieldDecorator('file', {
              rules: [{required: true, message:''}],
            })(
              <Upload {...props} style={{width:'100%'}}>
                <Button type={'primary'}>上传原文件</Button>
              </Upload>
            )}

          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={'注意'}
          >
            <div>
            <p >开始导入行号最小为2,默认最大行号为Excel行数 </p>
            </div>
          </FormItem>
        </Form>

      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);
